package com.project.forlearning.controller;

import com.project.forlearning.service.BackReportResourceService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 举报表操作
 */
@RequestMapping("report")
@Api(value = "CheckResourceController", tags={"后台举报相关的API"})
@RestController
@CrossOrigin
public class BackReportResourceController {

    @Autowired
    private BackReportResourceService reportResourceService;

    @ApiOperation("用户点击举报提交之后，添加到举报表中")
    @PostMapping("{resourceId}/{userId}")
    public String addReportResource(
            @ApiParam(value = "举报资源编号", required = true) @PathVariable("resourceId") int resourceId,
            @ApiParam(value = "举报人编号", required = true) @PathVariable("userId") int userId,
            @ApiParam(value = "举报原因", required = true) @RequestParam(value = "reason", required = false, defaultValue = "") String reason,
            @ApiParam("举报详情") @RequestParam(value = "reportDetails", required = false, defaultValue = "") String reportDetails
    ){
        return reportResourceService.addReportResource(resourceId, userId, reason, reportDetails);
    }

    @ApiOperation("根据举报编号删除对应的举报信息")
    @DeleteMapping("{reportId}")
    public String deleteReportResource(@ApiParam(value = "举报编号 注意区分不是举报资源编号", required = true) @PathVariable int reportId){
        return reportResourceService.deleteReportResource(reportId);
    }

    @ApiOperation("查询举报表中的某个信息")
    @GetMapping("{reportId}")
    public String queryReportResourceOne(@ApiParam(value = "举报编号", required = true) @PathVariable int reportId){
        return reportResourceService.queryReportResourceOne(reportId);
    }

    @ApiOperation("查询举报表中的全部信息")
    @GetMapping()
    public String queryReportResource(){
        return reportResourceService.queryReportResource();
    }

}
